import logging
from datetime import datetime

logger =logging.getLogger()

class statistics:
    '''
    统计数据集的一些信息。
    '''

    # 记录日志的时间范围
    log_start_time = 999999999999999999999999999999
    log_end_time = 0

    # 记录处理的文件信息
    handle_files = []

    # 记录边的类型，个数
    edge_type = {}

    # 读取的记录条数
    json_line = 0

    # 记录边个数
    edge_num = 0

    # 记录节点个数
    node_num = 0

    # 记录程序处理时间信息
    read_node_spend = 0
    store_edge_spend = 0
    write_kinds_of_files_spend = 0

    # 记录vertex_filter 过滤节点情况
    invilid_vertex_num = 0

    # 记录边处理 store_edge_info 的  相关情况
    loss_edge_num = 0
    generated_edge_num = 0

    unhandle_egde_type = []
    unhandle_egde_num = 0

    @staticmethod
    def show():
        info = f"处理的文件有{statistics.handle_files}\n"
        info += "共读取{}行数据\n边总数{}，过滤边{}。\t节点总数{},过滤节点{}\n生成图的节点{}、边{}\n".format(\
            statistics.json_line, statistics.edge_num, statistics.loss_edge_num, \
            statistics.node_num, statistics.invilid_vertex_num,statistics.node_num-statistics.invilid_vertex_num,\
            statistics.generated_edge_num)

        info += f"没有处理的边类型有{statistics.unhandle_egde_type}\n没有处理的边数量为{statistics.unhandle_egde_num}\n"

        info_handle = '从读取文件到节点数据处理完成共{}s\n边信息写入共计时{}\n写入各种文件共计时{}s\n'.format(
            statistics.read_node_spend, statistics.store_edge_spend, statistics.write_kinds_of_files_spend)

        info_time = "事件发生时间从{}\t到\t{}\n".format(
            datetime.utcfromtimestamp(statistics.log_start_time / 1e9).strftime('%Y-%m-%d %H:%M:%S.%f')[:-3],
            datetime.utcfromtimestamp(statistics.log_end_time / 1e9).strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])

        result = info_time + info + info_handle

        logger.info(result)

        return result